<!--
 * @Author       : lg
 * @Date         : 2022-06-24 22:44:09
 * @LastEditors  : lg
 * @LastEditTime : 2022-06-24 22:47:23
 * @FilePath     : \TwoWeeksFaceTest\ws-server\server\ws-p2p-1.html
 * @description  :
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ws - page1</title>
</head>
<body>
    <p>websocket</p>
    <button id="btn-send">发送消息</button>
    <script>
        // 浏览器自带，创建websocket实例，传入对应服务端地址
        const ws = new WebSocket('ws://127.0.0.1:3000');
        ws.onopen = () => {
            console.info('opened');
            ws.send('client1 opened');
        }
        ws.onmessage = (event) => {
            console.info('client1 收到了信息：'+event.data);
        }
        const btnSend = document.getElementById('btn-send');
        btnSend.addEventListener('click', () => {
            ws.send('client1 click send msg');
        });
    </script>
</body>
</html>
